package com.buss.customer.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.buss.core.dic.RecordStatus;
import com.buss.core.model.User;

/**
 * 客户/供应商信息
 * @author gykl
 *
 */
@Entity
@Table(name = "customer_customer")
@TableGenerator(name="customer_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
	pkColumnValue="customer_seq",valueColumnName="seq_val",table="customer_pk_sequence")
public class Customer implements Serializable{

	private static final long serialVersionUID = 526531946552149790L;

	/**表主键，客户/供应商编码*/
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="customer_pk_sequence")
	private Long id;
	
	/**单位ID*/
	@Column(length=20,nullable=false)
	private String companyId;
	
	/**客户/供应商类别*/
	@ManyToOne(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
	@JoinColumn(nullable=false,name="classId")
	private CustomerClass customerClass;
	
	/**客户/供应商名称*/
	@Column(length=200,nullable=false)
	private String name;
	
	/**快捷码*/
	@Column(length=200,nullable=false)
	private String mnemonic;
	
	/**单位电话*/
	@Column(length=50)
	private String telPhone;
	
	/**单位网址*/
	@Column(length=200)
	private String website;
	
	/**单位地址*/
	@Column(length=200)
	private String address;
	
	/**邮政编码*/
	@Column(length=10)
	private String post;
	
	/**传真号码*/
	@Column(length=50)
	private String fax;
	
	/**税务登记号*/
	@Column(length=50)
	private String tax;
	
	/**客户来源*/
	@ManyToOne(cascade=CascadeType.REFRESH,fetch=FetchType.EAGER)
	@JoinColumn(name="sourceId")
	private CustomerSource source;
	
	/**供应商所属销售员*/
	@ManyToMany(cascade=CascadeType.REFRESH,fetch=FetchType.LAZY)
	@JoinTable(name="customer_customer_sale",inverseJoinColumns={@JoinColumn(name="salesId")},
		joinColumns={@JoinColumn(name="customerId")})
	private List<User> saleses;
	
	/**是否开放给销售人员
	 *如果开放给销售人员，那么每个销售人员都能对该客户/供应商进行业务往来
	 */
	private Boolean isOpenToSales;
	
	/**应收限额*/
	@Column(precision=10,scale=2)
	private Float receivableLimit;
	
	/**应收额*/
	@Column(precision=10,scale=2)
	private Float receivables;
	
	/**应付限额*/
	@Column(precision=10,scale=2)
	private Float payableLimit;
	
	/**应付额*/
	@Column(precision=10,scale=2)
	private Float payables;
	
	/**是否客户*/
	private Boolean isCustomer;
	
	/**是否供应商*/
	private Boolean isSupplier;
	
	/**备注*/
	@Column(length=254)
	private String intro;
	
	/**当前状态*/
	@Column(length=20)
	@Enumerated(value=EnumType.STRING)
	private RecordStatus status;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	public CustomerClass getCustomerClass() {
		return customerClass;
	}

	public void setCustomerClass(CustomerClass customerClass) {
		this.customerClass = customerClass;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMnemonic() {
		return mnemonic;
	}

	public void setMnemonic(String mnemonic) {
		this.mnemonic = mnemonic;
	}

	public String getTelPhone() {
		return telPhone;
	}

	public void setTelPhone(String telPhone) {
		this.telPhone = telPhone;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPost() {
		return post;
	}

	public void setPost(String post) {
		this.post = post;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getTax() {
		return tax;
	}

	public void setTax(String tax) {
		this.tax = tax;
	}

	public CustomerSource getSource() {
		return source;
	}

	public void setSource(CustomerSource source) {
		this.source = source;
	}

	public List<User> getSaleses() {
		return saleses;
	}

	public void setSaleses(List<User> saleses) {
		this.saleses = saleses;
	}

	public Boolean getIsOpenToSales() {
		return isOpenToSales;
	}

	public void setIsOpenToSales(Boolean isOpenToSales) {
		this.isOpenToSales = isOpenToSales;
	}

	public Float getReceivableLimit() {
		return receivableLimit;
	}

	public void setReceivableLimit(Float receivableLimit) {
		this.receivableLimit = receivableLimit;
	}

	public Float getReceivables() {
		return receivables;
	}

	public void setReceivables(Float receivables) {
		this.receivables = receivables;
	}

	public Float getPayableLimit() {
		return payableLimit;
	}

	public void setPayableLimit(Float payableLimit) {
		this.payableLimit = payableLimit;
	}

	public Float getPayables() {
		return payables;
	}

	public void setPayables(Float payables) {
		this.payables = payables;
	}

	public Boolean getIsCustomer() {
		return isCustomer;
	}

	public void setIsCustomer(Boolean isCustomer) {
		this.isCustomer = isCustomer;
	}

	public Boolean getIsSupplier() {
		return isSupplier;
	}

	public void setIsSupplier(Boolean isSupplier) {
		this.isSupplier = isSupplier;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public RecordStatus getStatus() {
		return status;
	}

	public void setStatus(RecordStatus status) {
		this.status = status;
	}
	
	
}
